[WIP][SQL] Put check in ExpressionEncoder.fromRow to ensure we can convert deserialized object to required type #16546
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Two problems are addressed in this patch.
Seq[_]
which doesn't have element typeCurrently, in
ScalaReflection.serializerFor
, we try to serialize all sub types ofSeq[_]
. But forRange
which is aSeq[Int]
and doesn't have element type,serializerFor
will fail and show mystery messages:This patch tries to fix this by considering the types without element type.
We serialize the objects with common super class such as
Seq[_]
to a common internal data. But when we want to deserialize the internal data back to the original objects, we will encounter the problem of initialization of different types of objects.For example, we deserialize the data serialized from
Seq[_]
toWrappedArray
. It works when we serialize data ofSeq[_]
. If we try to serialize data of subclass ofSeq[_]
(for exampleRange
) which is not assignable fromWrappedArray
, there will be runtime error when converting deserialized data to the required subclass ofSeq[_]
.Except for explicitly writing down the rule to deserialize each subclass of
Seq[_]
, I think the feasible solution is to check if we can convert deserialized data to the required type. This patch puts the check intoExpressionEncoder.fromRow
. Once the requirement is not matched, we show a reasonable message to users.How was this patch tested?
Jenkins tests.
Please review http://spark.apache.org/contributing.html before opening a pull request.